<?php require_once('../../core/import.php');?>
<?php User::Permission('ACCOUNT_ADD'); ?>
<?php
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
        #图片处理
        $Result=Upload::Probe($_FILES['Logo'],Config::UPLOAD_ATTACHMENT_SIZE_IMAGE,Config::UPLOAD_ATTACHMENT_EXT_IMAGE,Config::PATH_UPLOAD_ATTACHMENT_TEMP);
        
        #如果重新上传了图片，处理
        $FileName=NULL;
        if($Result['error']!=UPLOAD_ERR_NO_FILE)    //如果上传了文件
        {
            switch($Result['error'])
            {
                case UPLOAD_ERR_OK:
                    $FileName=Upload::Execute($_FILES['Logo'],Config::PATH_UPLOAD_ATTACHMENT_TEMP);
                break;
                case Upload::UPLOAD_ERR_CUSTOM_EXT:
                    exit('{"Number":"2","Description":"LOGO格式不正确，只能是：'.join(',',Upload::$UPLOAD_EXT_IMAGE).'。"}');
                break;
                case Upload::UPLOAD_ERR_CUSTOM_SIZE:
                    exit('{"Number":"3","Description":"LOGO大小超过了限制，不能超过：'.Functions::SizeFormat(Config::UPLOAD_ATTACHMENT_SIZE_IMAGE).'。"}');
                break;
                default :
                    exit('{"Number":"4","Description":"LOGO上传失败。错误代码：'.$Result['error'].'，错误描述：'.$Result['message'].'。"}');
            }
        }
        
	  $Username=Functions::FormArgs('Username');
	  $Password=Functions::FormArgs('Password');
	  $RegisterdCapital=Functions::FormArgs('RegisterdCapital');
	  $EstablishedTime=Functions::FormArgs('EstablishedTime');
	  $Linkman=Functions::FormArgs('Linkman');
	  $Department=Functions::FormArgs('Department');
	  $Position=Functions::FormArgs('Position');
	  $Password_Again=Functions::FormArgs('Password_again');
	  $Data=DB::GetRows('select id,username from `account` where username=\''.$Username.'\'');
	  if(count($Data)>0){
		exit('{"Number":"4","Description":"该用户已存在"}');	  
	  }

	  if(!$Username)
	  {
		exit('{"Number":"4","Description":"用户名不能为空"}');	  
	  }
	  if(!$Password)
	  {
		exit('{"Number":"4","Description":"密码不能为空"}');	  
	  }
	  if(!$Password_Again)
	  {
		exit('{"Number":"4","Description":"确认密码不能为空"}');	  
	  }
	  if($Password!=$Password_Again)
	  {
		exit('{"Number":"4","Description":"两次密码输入不一致"}');	  
	  }
	  if(!$Linkman)
	  {
		exit('{"Number":"4","Description":"联系人不能为空"}');	  
	  }
	  if(!$Department)
	  {
		exit('{"Number":"4","Description":"部门不能为空"}');	  
	  }

        #上传数据
	  $Password=Account::EncryptPassword($Password,$Username);
	  $Data=array
		(
			'Username'=>$Username,
			'Password'=>$Password,
			'Datetime'=>date('Y-m-d G:i:s'),
			
			'CompanyName'=>Functions::FormArgs('CompanyName'),
			'Model'=>Functions::FormArgs('Model'),
			'RegisterdCapital'=>Functions::FormArgs('RegisterdCapital'),
			'EstablishedTime'=>Functions::FormArgs('EstablishedTime'),
			'Trade_Class'=>Functions::FormArgs('Trade_Class_Value'),
			'Trade_Subclass'=>Functions::FormArgs('Trade_Subclass_Value'),			
			'Partner'=>Functions::FormArgs('Partner'),
			'Product'=>Functions::FormArgs('Product'),
			'Province'=>Functions::FormArgs('Province'),
			'City'=>Functions::FormArgs('City'),
			'Address'=>Functions::FormArgs('Address'),
			'Intro'=>Functions::FormArgs('Intro',60000,FALSE),
			'Linkman'=>Functions::FormArgs('Linkman'),
			'Sex'=>Functions::FormArgs('Sex'),
			'Department'=>Functions::FormArgs('Department'),
			'Position'=>Functions::FormArgs('Position'),
			'URL'=>Functions::FormArgs('URL'),
			'Phone'=>Functions::FormArgs('Phone'),
			'Fax'=>Functions::FormArgs('Fax'),
			'MSISDN'=>Functions::FormArgs('MSISDN'),
			'QQ'=>Functions::FormArgs('QQ'),
			'MSN'=>Functions::FormArgs('MSN'),

			'M_IsTop'=>Functions::FormArgs('M_IsTop')
			
		);
		if(Functions::FormArgs('M_IsTop')>0) 
		{
			$Data['M_IsTop_Datetime']=date('Y-m-d G:i:s');
		}
		if($FileName)
		{
			$Data['Logo']=$FileName;
		}
		//Functions::Print_r($Data);
		DB::Insert('account',$Data);
		
		if(Functions::FormArgs('M_Email')>0) 
		{
			DB::Insert('account_email_verification',array
			(
				'Account'=>Functions::FormArgs('Username'),
				'Datetime'=>date('Y-m-d G:i:s')
			));
		}
		if(Functions::FormArgs('M_locked')>0) 
		{
			DB::Insert('account_locked',array
			(
				'Account'=>Functions::FormArgs('Username'),
				'Datetime'=>date('Y-m-d G:i:s')
			));
		}
		if(Functions::FormArgs('M_Vip')>0) 
		{
			DB::Insert('account_vip',array
			(
				'Account'=>Functions::FormArgs('Username'),
				'Datetime'=>date('Y-m-d G:i:s')
			));
		}

		if(Functions::FormArgs('M_Integrity')>0) 
		{
			DB::Insert('account_integrity',array
			(
				'Account'=>Functions::FormArgs('Username'),
				'Datetime'=>date('Y-m-d G:i:s')
			));
		}
		
		if(Functions::FormArgs('M_IsPowerful')>0) 
		{
			DB::Insert('account_integrity',array
			(
				'Account'=>Functions::FormArgs('Username'),
				'Datetime'=>date('Y-m-d G:i:s')
			));
		}		
			//代为注册
			DB::Insert('management_user_register',array
			(
				'User'=>User::Session('Username'),
				'Account'=>Functions::FormArgs('Username'),
				'Datetime'=>date('Y-m-d G:i:s')
			));
			$guid=Functions::GUID();
			$email=new Email();
			$email->IsHTMLEmail=TRUE;
			$email->Recipients=$Username;
			$email->Title='中国船舶配套，注册电子邮件验证。';
			$email->Content='感谢您注册中国船舶配套网，请点击下面的链接验证您的Email。<br/>';
			$email->Content.='http://www.shipinall.cn/exec.php?action=account_register_email&';
			$email->Content.='number='.urlencode($guid).'<br/>';
			$email->Content.='--中国船舶配套网';
			$email->Send();
		//信息统计
		User::Statistics_User('ACCOUNT_ADD','account','会员版块');
		echo '{"Number":"0","Description":"发布成功"}';
    }
?>